package hawk.example.jdk.stream;

import java.util.List;
import java.util.stream.Stream;

public abstract class Shower {
    public static <T> void show(String title, Stream<T> stream) {
        final int SIZE = 10;
        List<T> firstElements = stream.limit(SIZE + 1).toList();
        System.out.print(title + ": ");
        for (int i = 0; i < firstElements.size(); i++) {
            if (i > 0)
                System.out.print(", ");
            if (i < SIZE) {
                Object o = firstElements.get(i);
                if (o instanceof Stream) {
                    show("sub", (Stream) o);
                } else {
                    System.out.print(o);
                }
            } else
                System.out.print("...");
        }
        System.out.println();
    }
}
